import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:status_bar_control/status_bar_control.dart';
import '../../../base/base_stateful_page.dart';
import '../widgets/article_nav_widget.dart';
import '../widgets/article_tool_widget.dart';
import '../widgets/article_web_widget.dart';
import 'information_detail_cubit.dart';

class InformationDetailPage extends BasePage {
  final int entityId;
  const InformationDetailPage({super.key, required this.entityId});

  @override
  BasePageState<BasePage> getState() {
    return _InformationDetailPageState();
  }
}

class _InformationDetailPageState extends BasePageState<InformationDetailPage> {
  @override
  void initState() {
    super.initState();
    isRenderHeader = false;
    pageBgColor = const Color(0xFFF3F4F8);

    Future.delayed(const Duration(milliseconds: 100)).then((value) async {
      StatusBarControl.setStyle(StatusBarStyle.DARK_CONTENT);
    });
    _getData();
  }

  /// 请求数据
  _getData() {
    InformationDetailCubit cubit = context.read<InformationDetailCubit>();
    cubit.geDetailData('pc/items/info', widget.entityId);
  }

  Widget mainWidget(InformationDetailState state) {
    return Stack(
      children: [
        Padding(
          padding: EdgeInsets.only(top: statusBarH + kToolbarHeight, bottom: bottomSafeBarH + 60.h),
          child: ArticleWebWidget(
            htmlStr: state.model!.newsContent,
          ),
        ),
        const Positioned(child: ArticleNavWidget()),
        Positioned(
            bottom: bottomSafeBarH,
            child: ArticleTooWidget(
              model: state.model!,
            ))
      ],
    );
  }

  @override
  Widget buildPage(BuildContext context) {
    return BlocBuilder<InformationDetailCubit, InformationDetailState>(
      builder: (context, state) {
        return resultWidget(state, (baseState, context) => mainWidget(state), refreshMethod: () {
          _getData();
        });
      },
    );
  }
}
